#!/bin/bash 

#####################################
HP-UX

#####################################


#####################################
AIX
# /etc/rc.d/rc2.d/Soradb.sh 
#####################################


#####################################
LINUX
#cp alloracle /etc/rc.d/init.d/alloracle 
#chkconfig --add alloracle
#chkconfig --list alloracle

######################################
#export ORACLE_SID=orcl 

export ORACLE_HOME=/usr/app/oracle/product/10.2.0/db_l
export PATH=$PATH:$ORACLE_HOME/bin 
ORA_OWNR="oracle" 


# if the executables do not exist -- display error 
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ] 
then 
    echo "Oracle startup: cannot start" 
    exit 1 
fi 
# lock file  check
LOCK_FILE=/var/lock/oracle 

# depending on parameter -- startup, shutdown, restart 
# of the instance and listener or usage display 
case "$1" in 
  start) 

        if [  -f $LOCK_FILE ] 
        then 
            echo "rm $LOCK_FILE do again" 
            exit 1 
        fi 

    # Oracle listener and instance startup 
     echo  "Starting Oracle: " 
     su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start "  
     su $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"  
    touch  $LOCK_FILE
     su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole" 
     su $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl start" 
    echo "OK" 
    ;; 
 
  stop) 

        if [  ! -f $LOCK_FILE ] 
        then 
            echo "database is no run " 
            exit 1 
        fi 

    # Oracle listener and instance shutdown 
    echo  "Shutdown Oracle: " 
    su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole" 
    su $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl stop" 
    su $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut" 
    su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop" 
    rm -f $LOCK_FILE
    echo "OK" 
    ;; 
 
  reload|restart) 
    $0 stop 
    $0 start 
    ;; 
  *) 
    echo "Usage: `basename $0` start|stop|restart|reload" 
    exit 1 
esac 
exit 0


